Thread: ' Mutex ' in namespace ' std ' does not name a type | ??

  1. #1
    Registered User
    Join Date
    Nov 2015
    Posts
    119

    ' Mutex ' in namespace ' std ' does not name a type | ??

    Good all day! Error-D:\Classes\mutex1\mutex1.cpp | 9 | error: ' mutex ' in namespace ' std ' does not name a type |

    That is, write please!? In fact, this should not and cannot be?


    Code:
    #include <iostream>
    #include <chrono>
    #include <thread>
    #include <mutex>
    #include <map>
    #include <string>
     
    std::map<std::string, std::string> g_pages;
    std::mutex g_pages_mutex;
    Last edited by Dmy; 08-03-2017 at 04:58 PM.

  2. #2
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    Good joy to you muchly so!

    Please don't post code you haven't run yourself.
    The code you posted works just fine.
    However, the title of your post says Mutex, not mutex.
    So presumably your original code had a capital M, which is wrong.

  3. #3
    Registered User
    Join Date
    Nov 2015
    Posts
    119
    Thank you so much! But no, the mutex is spelled with a small letter. It looks like it's probably different mutex and Mutex.
    Anyway, I'm reading about everywhere mutex, see written with examples. And I can't compile fails to collect samples.
    Here's an example here mutex - C++ Reference and here std::mutex — cppreference.com for example yet.

    I first just wanted to compile this code
    Code:
    #include <mutex>
    
    void foo()
    {
        std::mutex m;
    }
    
    
    #include <iostream>
    #include <cstdlib>
    
    #include <timertt/all.hpp>
    
    using namespace std;
    using namespace std::chrono;
    using namespace timertt;
    
    int main()
    {
       timer_wheel_thread_t tt;
    
       // Timer thread must be started before activation of timers.
       // Таймерний потік повинен запускатися перед активацією таймерів.
       tt.start();
    
       // The simple single-shot timer.
       // простий одноразовий таймер.
       tt.activate( milliseconds( 20 ),
             []() { cout << "Simple one-shot" << endl; } );
    
       // The simple periodic timer.
       // Will work until timer thread finished.
       // простий періодичний таймер.
          // Буде працювати, поки закінчиться таймер.
       tt.activate( milliseconds( 20 ), milliseconds( 20 ),
             []() {
                static int i = 0;
                cout << "Simple periodic (" << i << ")" << endl;
                ++i;
             } );
    
       // Allocation of timer and explicit activation.
       //  озподіл таймера та явної активації.
       auto id1 = tt.allocate();
       tt.activate( id1, milliseconds( 30 ),
             []() {
                cout << "Preallocated single-shot timer" << endl;
             } );
    
       // Periodic timer with timer preallocation, explicit activation
       // and deactivation from the timer action.
       // Періодичний таймер з попереднім розподілом таймера, явна активація
          // і деактивація з дії таймера.
       auto id2 = tt.allocate();
       tt.activate( id2, milliseconds( 40 ), milliseconds( 15 ),
             [id2, &tt]() {
                static int i = 0;
                cout << "Preallicated periodic (" << i << ")" << endl;
                ++i;
                if( i > 2 )
                   tt.deactivate( id2 );
             } );
    
       // Single-shot timer with explicit activation and deactivation
       // before timer event.
       // одноразовий таймер з явною активацією та деактивізацією
          // перед таймером
       auto id3 = tt.allocate();
       tt.activate( id3, milliseconds( 50 ),
             []() {
                cerr << "This timer must not be called!" << endl;
                std::abort();
             } );
       tt.deactivate( id3 );
    
       // Wait for some time.
       // Зачекайте деякий час.
       this_thread::sleep_for( milliseconds( 200 ) );
    
       // Finish the timer thread.
       // Завершити потік таймера.
       tt.shutdown_and_join();
    }
    and got the same error in one of the plug-in files.

    Can I still need some heders connect to compile properly, all settings of the compiler seems in order ...

    In General, what to do?
    Last edited by Dmy; 08-04-2017 at 02:21 PM.

  4. #4
    Guest
    Guest
    So anything involving std::mutex, like the examples from the links you posted, don't compile and give an error?

    Code:
    #include <mutex>
    
    int main()
    {
        std::mutex m;
    }
    ^ This gives an error? If so, then maybe your C++ compiler hasn't implemented std::mutex, or you're not compiling as C++11?

  5. #5
    Registered User
    Join Date
    Nov 2015
    Posts
    119
    Всі, саме всі std::mutex дають помилку. От цікаво! All, just all std :: mutex make a mistake. That's interesting! All, it's all std: mutex gives an error. That's interesting!

  6. #6
    Registered User
    Join Date
    Nov 2015
    Posts
    119
    All, it's all std: mutex gives an error. That's interesting!

    I compiling as C++0x

    maybe your C++ compiler hasn't implemented std::mutex
    Yes, I guess it's something like that.
    Last edited by Dmy; 08-05-2017 at 03:53 AM.

  7. #7
    Guest
    Guest
    No point in limiting yourself by using an outdated compiler, unless you're forced to by your environment. It doesn't cost you a dime to get something up-to-date.

  8. #8
    Registered User
    Join Date
    Nov 2015
    Posts
    119
    Tell me please, and I can download new inkludy needed on drive d, without affecting the c drive which is full?
    How best to instruct the compiler to new inkludy?
    I have an old computer with 32 bits.

    Where better to download?

    D:\codeblocks-16.01mingw-nosetup\mingw\include will fit me?
    Last edited by Dmy; 08-05-2017 at 05:37 AM.

  9. #9
    Registered User
    Join Date
    Nov 2015
    Posts
    119
    I don't remember any settings codeblocks.
    How to better include and what better connect to use std: mutex?
    What action?
    In General my codeblocks good configured well connected many libraries, and it still worked.
    Is this better?

    I don't remember any of the codeblocks settings.
    How best and which include best to connect to use std: Mutex?
    What kind of action?
    In general, my codeblocks is well configured, many libraries are well connected, and so far I've been doing it.
    Is this better?

  10. #10
    Guest
    Guest
    I'm sorry, I don't think I can help you. I don't use Codeblocks and the language barrier is too big. In your own interest, I really think you should talk to fellow Russians, of whom I'm sure there are tens of thousands of C++ developers.

    Make sure you install the latest version of Codeblocks and try following this guide. Maybe that'll work.

  11. #11
    Registered User
    Join Date
    Nov 2015
    Posts
    119
    Yeah, I see. Thank you.

  12. #12
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    You need to understand that Code::Blocks is an Editor/IDE and it is not an Compiler!!

    You need to learn about your Compiler! It might have a setting to change to C++11 support.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 11
    Last Post: 03-13-2013, 12:28 PM
  2. Friend of namespace or of namespace function?
    By Programmer_P in forum C++ Programming
    Replies: 18
    Last Post: 03-13-2011, 06:46 PM
  3. Mutex question
    By laertius in forum C Programming
    Replies: 5
    Last Post: 09-17-2007, 12:16 PM
  4. Mutex in C
    By jgs in forum Windows Programming
    Replies: 4
    Last Post: 05-21-2005, 07:11 AM
  5. Mutex
    By DutchStud in forum Windows Programming
    Replies: 2
    Last Post: 11-06-2001, 12:09 AM

Tags for this Thread